package com.yanqu.road.server.pb;

import com.yanqu.road.entity.clinic.*;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.pb.clinic.ClinicProto;
import com.yanqu.road.utils.property.PropertyHelper;

/**
 * @author ：zfr
 * @date ：2021/3/3 11:12
 */
public class ClinicPb {
    public static ClinicProto.ClinicDataSync.Builder parseClinicData(UserClinicData userClinicData) {
        ClinicProto.ClinicDataSync.Builder builder = ClinicProto.ClinicDataSync.newBuilder();
        for (DepartmentData data : userClinicData.getDepartmentMap().values()) {
            builder.addDepartment(parseDepartment(data));
        }
        for (DiseaseData data : userClinicData.getDiseaseDataMap().values()) {
            builder.addDisease(parseDisease(data));
        }
        builder.addAllPatient(userClinicData.getUnLockPatientList());
        for (PatientClientState patientClientState : userClinicData.getPatientClientStates()) {
            builder.addCuredPatient(parsePatient(patientClientState));
        }
        for (WaitCurePatient patient : userClinicData.getWaitCurePatientList()) {
            builder.addWaitCuredPatient(parsePatient(patient));
        }
        builder.setReceptPatientNum(userClinicData.getCurReceptPatientNum());
        builder.setPatientNum(userClinicData.getPatientNum());
        builder.setLastReceptTime(userClinicData.getLastCuredTime());
        builder.setRewardNum(userClinicData.getClinicRewardData().getRewardNum());
        builder.setEventNpc(userClinicData.getEventNpc());
        builder.setScore(userClinicData.getClinicScore());
        builder.setCuredPatientNum((int) userClinicData.getCuredPatientCount());
        builder.setLastGetPatientTime(userClinicData.getLastGetPatientTime());
        builder.setCurEventId(userClinicData.getCurEvenId());
        builder.setEventCompeteNum(userClinicData.getEventCompeteNum());
        return builder;
    }

    public static ClinicProto.DepartmentTemp.Builder parseDepartment(DepartmentData data) {
        ClinicProto.DepartmentTemp.Builder builder = ClinicProto.DepartmentTemp.newBuilder();
        builder.setType(data.getType());
        builder.setLevel(data.getLevel());
        return builder;
    }

    public static ClinicProto.DiseaseTemp.Builder parseDisease(DiseaseData data) {
        ClinicProto.DiseaseTemp.Builder builder = ClinicProto.DiseaseTemp.newBuilder();
        builder.setDiseaseId(data.getId());
        builder.setSkillLevel(data.getLevel());
        builder.setValue(data.getValue());
        return builder;
    }

    public static ClinicProto.PatientTemp.Builder parsePatient(PatientClientState patientClientState) {
        ClinicProto.PatientTemp.Builder builder = ClinicProto.PatientTemp.newBuilder();
        builder.setDiseaseId(patientClientState.getDiseaseId());
        builder.setPatientId(patientClientState.getPatientId());
        builder.setLastSendTime(patientClientState.getLastSendTime());
        builder.setId(patientClientState.getId());
        return builder;
    }

    public static ClinicProto.PatientTemp.Builder parsePatient(WaitCurePatient patient) {
        ClinicProto.PatientTemp.Builder builder = ClinicProto.PatientTemp.newBuilder();
        builder.setPatientId(patient.getPatientId());
        builder.setDiseaseId(patient.getDiseaseId());
        builder.setId(patient.getId());
        return builder;
    }

    public static void parseClinicReward(ClinicRewardData data, ClinicProto.GetClinicRewardListRespMsg.Builder respMsg) {
        respMsg.setClinicScore((int) data.getClinicScore());
        respMsg.setReward(PropertyHelper.parsePropertyToString(data.getReward()));
        for (DiseaseReward diseaseReward : data.getDiseaseRewardMap().values()) {
            ClinicProto.DiseaseValueRewardTemp.Builder builder = ClinicProto.DiseaseValueRewardTemp.newBuilder();
            builder.setDiseaseId(diseaseReward.getId());
            builder.setNum(diseaseReward.getNum());
            builder.setValue((int) diseaseReward.getValue());
            respMsg.addDiseaseReward(builder);
        }
    }

    public static ClinicProto.VisitOtherClinicRespMsg.Builder parseVisitClinicMsg(UserClinicData userClinicData, UserInfo userInfo) {
        ClinicProto.VisitOtherClinicRespMsg.Builder respMsg = ClinicProto.VisitOtherClinicRespMsg.newBuilder();
        respMsg.setUserData(PlayerPb.parsePlayerBaseTempMsg(userInfo));
        for (DepartmentData departmentData : userClinicData.getDepartmentMap().values()) {
            respMsg.addDepartment(parseDepartment(departmentData));
        }
        for (DiseaseData diseaseData : userClinicData.getDiseaseDataMap().values()) {
            respMsg.addDisease(parseDisease(diseaseData));
        }
        respMsg.addAllPatient(userClinicData.getUnLockPatientList());
        respMsg.setRewardNum(userClinicData.getClinicRewardData().getRewardNum());
        respMsg.setEventNpc(userClinicData.getEventNpc());
        return respMsg;
    }
}
